<template>
<!-- 我的收藏 -->
    <div>
        <el-card class="box">
          <div class="div1">
            <div class="div1-1" @click="select(0)" :class="{'click_color':click_color_index==0}">
              视频  
            </div>
            <div class="div1-1" @click="select(1)" :class="{'click_color':click_color_index==1}">
              文章
            </div>
            <div class="div1-1" @click="select(2)" :class="{'click_color':click_color_index==2}">
              直播
            </div>
          </div>
          <div class="div2">
            <div class="div33">
              <div class="div33-1">
                <p class="div33-1-p">{{type}}信息</p>
              </div>
              <div class="div33-2">
                <p class="div33-1-p1">金额</p>
              </div>
              <div class="div33-3">
                <p class="div33-1-p1">操作</p>
              </div>
            </div>
            <div class="div4">

            </div>
          </div>

          <div class="div-4">
              <div class="div-4-box"  v-for="item in tableData" :key="item.id">
                <div class="div4-2">
                  <div class="div4-2-1">
                    <div class="div4-2-1-1">
                      <img class="img1" :src="'http://101.43.223.224:8765/image/getImageById?id='+item.imageId" />
                    </div>
                  </div>
                  <div class="div4-2-2">
                    <p>{{item.courseTitle}}</p>
                  </div>
                  <div class="div4-2-3">
                    <p>{{item.tname}}</p>
                  </div>
                  <div class="div4-2-4">
                    <p v-if='item.payType == 0'>免费</p>
                    <p v-if='item.payType == 1'>
                      <span class="span-1">{{item.price}}元</span>
                    </p>
                  </div>
                  <div class="div4-2-5">
                    <p @click="updateCollectDelFlagByUserId(item.courseId)"><el-button type="text">取消收藏</el-button></p>
                  </div>
                </div>
              </div>
          </div>

        </el-card>
    </div>
</template>
<script>
export default {
  name: 'MyCollect',
  data () {
    return {
      // 收藏类型
      type: '',
      // 点击切换颜色
      click_color_index: 0,
      // 表格数据
      tableData:[]
    }
  },
  mounted () {
    // 默认查看视频内容
    this.select(0)
  },
  methods: {
    // 取消收藏
    updateCollectDelFlagByUserId(data) {
     this.$axios.put('/collect/updateCollectDelFlagByUserId?collectId='+data
      ).then(res => {
          if(res.data.flag){
              this.select(0)
              this.message('success', '取消收藏成功')
          }else{
              this.message('error', '取消收藏失败,请重新登录')
          }
      }).catch(err => {
          console.log(err)
      })
    },
    // 点击切换视频 文章 直播数据
    select (data) {
      this.click_color_index = data
      console.log(data)
      if (data == 0){
        this.type = '视频'
        this.selectCollectJoinCourse(data)
      }
      if (data == 1){
        this.type = '文章'
        this.selectCollectJoinCourse(data)
      }
      if (data == 2) {
        this.type = '直播'
        this.selectCollectJoinCourse(data)
      }
    },
    // 根据用户id和收藏类型查询数据
    selectCollectJoinCourse (data) {
      this.$axios.get('/collect/selectCollectJoinCourse',
          {
            params: {
              userId: window.sessionStorage.getItem('userId'),
              courseType: data
            }
          } 
        ).then(res => {
            if(res.data.flag){
                this.tableData = res.data.data
                console.log(this.tableData)
                this.message('success', '获取收藏信息成功')
            }else{
                this.message('error', '获取收藏信息失败,请重新登录')
            }
        }).catch(err => {
            console.log(err)
        })
    }
  }
}
</script>

<style scoped>
  .box {
    width: 900px;
    margin: 0 auto;
  }
  .div1 {
    width: 100%;
    height: 40px;
    background-color: #fff;
    margin-bottom: 10px;
  }
  .div1-1 {
    width: 60px;
    height: 100%;
    float: left;
    text-align: center;
    line-height: 40px;
    font-size: 20px;
    /* border-bottom: 1px solid rgb(32,128,247); */
    margin-left: 20px;
    cursor: pointer; 
  }
  .click_color {
    width: 60px;
    height: 100%;
    float: left;
    text-align: center;
    line-height: 40px;
    font-size: 20px;
    color: rgb(32,128,247);
    border-bottom: 1px solid rgb(32,128,247);
    margin-left: 20px;
    cursor: pointer; 
  }
  .div2 {
    width: 100%;
    height: 100%;
  }
  .div3 {
    width: 100%;
    height: 60px;
    background-color: rgb(32,128,247);
    border: 1px solid rgb(222,222,222);
  }
  .div33 {
    width: 100%;
    height: 24px;
    border: 1px solid rgb(245,248,250);
    /* border-bottom: 0.1px solid rgb(144,147,153); */
    font-weight: bold;
    margin-top: 10px;
  }
  .div33-1 {
    width: 550px;
    height: 100%;
    float: left;
  }
  .div33-2 {
    width: 150px;
    height: 100%;
    float: left;
  }
  .div33-3 {
    width: 150px;
    height: 100%;
    float: left;
  }
  .div33-1-p{
    width: 100%;
    height: 100%;
    font-size: 12px;
    text-align: left;
    margin-top: 4px;
    margin-left: 28px;
    color: rgb(161,169,178);
  }
  .div33-1-p1 {
    width: 100%;
    height: 100%;
    font-size: 12px;
    text-align: left;
    margin-top: 4px;
    margin-left: 4px;
    color: rgb(161,169,178);
  }
  .div-4 {
    width: 100%;
    height: 500px;
    /* background-color: red; */
  }
  .div4-1{
    width: 100%;
    height: 50px;
    background-color: rgb(245,248,250);
    border-radius: 10px;
    font-size: 16px;
  }
  .div4-1 p {
    width: 180px;
    height: 30px;
    margin-left: 16px;
    padding-top: 12px;
    font-size: 16px;
  }
  .div4-2 {
    width: 100%;
    height: 100px;
    /* background-color: rgb(36, 137, 205); */
    /* 边框变黑1px */
    border-bottom: 1px solid rgb(210,211,212);
  }
  .div4-2-1{
    width: 120px;
    height: 100px;
    float: left;
  }
  .div4-2-2 {
    width: 426px;
    height: 100px;
    float: left;
    font-size: 16px;
    /* background-color: greenyellow; */
  }
  .div4-2-3 {
    position: absolute;
    width: 80px;
    height: 20px;
    margin-left: 138px;
    margin-top: 60px;
    /* float: left; */
    /* background-color: red; */
  }
  .div4-2-3 p {
    margin-top: 0px;
    width: 80px;
    height: 20px;
    text-align: left;
    margin-left: 4px;
    /* background-color: antiquewhite; */
    font-size: 12px;
  }
  /* .div4-2-3 p{
    width: 90%;
    height: 40px;
    text-align: left;
    margin: 0 auto;
    margin-top: 40px;
    font-size: 16px;
  } */
  .div4-2-4 {
    width: 150px;
    height: 100px;
    float: left;
  }
  .div4-2-5{
    width: 150px;
    height: 100px;
    float: left;
  }
  .div4-2-5 p{
    width: 100px;
    margin-left: 10px;
    text-align: left;
    margin-top: 32px;
    font-size: 16px;
  }
  .div4-2-1-1 {
    width: 100px;
    height: 60px;
    margin: 0 auto;
    margin-top: 20px;
  }
  .div4-2-2 p{
    width: 90%;
    height: 40px;
    text-align: left;
    margin: 0 auto;
    margin-top: 30px;
    overflow: hidden;
    font-size: 16px;
  }
  
  .div4-2-4 p{
    width: 90%;
    height: 40px;
    text-align: left;
    margin: 0 auto;
    margin-top: 40px;
    font-size: 16px;
    color: red;
  }
  .div4-2-4-span{
    width: 90%;
    height: 40px;
    text-align: left;
    margin: 0 auto;
    margin-top: 40px;
    font-size: 16px;
  }
  .div-4-box {
    width: 100%;
    height: 100px;
    border-radius: 10px;
    /* margin-top: 20px; */
  }
  .img1 {
    width: 100%;
    height: 100%;
    background-size:100% 100%;
    background-repeat:no-repeat;
  }
  .span-1 {
    margin-left: 3px;
  }
</style>
